package com.lemon.smartsafetynew.net.services;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDangerFile;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDownloadVo;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenLevelVo;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenProcessItemVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * Created by Andrew on 2017/9/20.
 */

public class SafeHiddenServices extends BaseHttpServices {

    public static final String TAG = "ContactServices";

    public SafeHiddenServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static SafeHiddenServices init() {
        return new SafeHiddenServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static SafeHiddenServices init(Context context) {
        return new SafeHiddenServices(context);
    }

    /**
     * 获取隐患排查列表
     *
     * @param type
     * @param params
     * @param status 获取当前页面的状态信息
     *               （"1", "新建"）
     *               （"2", "整改"）
     *               （"3", "复查"）
     *               （"4", "结束"）
     */
    public void getSafeHiddenList(RefreshType type, LemonRequestParams params, String status) {

        HandlerCallback<List<SafeHiddenDownloadVo>> callback = new HandlerCallback<List<SafeHiddenDownloadVo>>(KeyConstants.URL_GET_SAFE_HIDDEN_LIST + status) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取隐患信息列表(新)
     * @param type
     * @param params
     */
    public void getSafeHiddenListNew(RefreshType type, LemonRequestParams params) {
        HandlerCallback<List<SafeHiddenDownloadVo>> callback = new HandlerCallback<List<SafeHiddenDownloadVo>>(KeyConstants.URL_GET_SAFE_HIDDEN_LIST_NEW) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_LIST_NEW, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

    /**
     * 获取单个隐患排查
     *
     * @param params
     */
    public void getSafeHiddenDto(LemonRequestParams params) {

        HandlerCallback<SafeHiddenDownloadVo> callback = new HandlerCallback<SafeHiddenDownloadVo>(KeyConstants.URL_GET_SAFE_HIDDEN ) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取隐患处理记录列表
     *
     * @param type
     * @param params
     */
    public void getSafeHiddenHandleRecords(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<SafeHiddenProcessItemVo>> callback = new HandlerCallback<List<SafeHiddenProcessItemVo>>(KeyConstants.URL_GET_SAFE_HIDDEN_RECORDS) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_RECORDS, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /**
     * 有附件创建隐患
     *
     * @param params
     * @param fileMap
     */
    public void createHidden(LemonRequestParams params, Map<String, File> fileMap) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_CREATE_SAFE_HIDDEN) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.CREATE_SAFE_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .addFiles("file", fileMap)
                .build().execute(callback);


    }

    /***
     * 有附件整改隐患
     * @param params
     * @param fileMap
     */
    public void rectifyHidden(LemonRequestParams params, Map<String, File> fileMap) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_RECTIFY_SAFE_HIDDEN) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.RECTIFY_SAFE_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .addFiles("file", fileMap)
                .build().execute(callback);


    }

    /***
     * 有附件复查隐患
     * @param params
     * @param fileMap
     */
    public void reviewHidden(LemonRequestParams params, Map<String, File> fileMap) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_REVIEW_SAFE_HIDDEN) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.REVIEW_SAFE_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .addFiles("file", fileMap)
                .build().execute(callback);

    }

    /**
     * 无附件创建隐患
     * @param params
     */
    public void createHiddenNoFile(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_CREATE_SAFE_HIDDEN_NO_FILE) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.CREATE_SAFE_HIDDEN_NO_FILE, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 无附件整改隐患
     * @param params
     */
    public void rectifyHiddenNoFile(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_RECTIFY_SAFE_HIDDEN_NO_FILE) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.RECTIFY_SAFE_HIDDEN_NO_FILE, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 无附件的复查隐患
     * @param params
     */
    public void reviewHiddenNoFile(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_REVIEW_SAFE_HIDDEN_NO_FILE) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.REVIEW_SAFE_HIDDEN_NO_FILE, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }


    /***
     * 根据隐患状态 查看隐患的附件
     * @param params
     */
    public void getHiddenAttachment(LemonRequestParams params) {

        HandlerCallback<List<String>> callback = new HandlerCallback<List<String>>(KeyConstants.URL_GET_SAFE_HIDDEN_ATTACHMENT) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_ATTACHMENT, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取没有上报的隐患排查列表
     *
     */
    public void getNotUploadHiddenList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<SafeHiddenDownloadVo>> callback = new HandlerCallback<List<SafeHiddenDownloadVo>>(KeyConstants.URL_GET_SAFE_HIDDEN_NOT_UPLOAD_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /**
     * 上报隐患
     *
     */
    public void reportSafeHidden(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_REPORT_SAFE_HIDDEN) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.REPORT_SAFE_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 根据隐患的操作id号 查看隐患的附件
     * @param params
     */
    public void getHiddenAttachmentByOperation(LemonRequestParams params) {

        HandlerCallback<List<SafeHiddenDangerFile>> callback = new HandlerCallback<List<SafeHiddenDangerFile>>(KeyConstants.URL_GET_SAFE_HIDDEN_ATTACHMENT_BY_ID) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_ATTACHMENT_BY_ID, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 【常熟项目】 获取安全隐患等级
     * @param params
     */
    public void getHiddenLevel(LemonRequestParams params) {

        HandlerCallback<List<SafeHiddenLevelVo>> callback = new HandlerCallback<List<SafeHiddenLevelVo>>(KeyConstants.URL_GET_SAFE_HIDDEN_LEVEL) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_SAFE_HIDDEN_LEVEL, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 【常熟项目】 生成现场检查意见书
     * @param params
     */
    public void generateSiteInspectionDoc(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_GENERATE_SITE_INSPECTION_DOC) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GENERATE_SITE_INSPECTION_DOC, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 【常熟项目】 生成责令限期整改指令书
     * @param params
     */
    public void generateOrderRectificationDoc(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_GENERATE_ORDER_RECTIFICATION_DOC) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GENERATE_ORDER_RECTIFICATION_DOC, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 【常熟项目】 生成整改复查意见书
     * @param params
     */
    public void generateRectificationReviewDoc(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_GENERATE_RECTIFICATION_REVIEW_DOC) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GENERATE_RECTIFICATION_REVIEW_DOC, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }

    /***
     * 【常熟项目】 获取令限期整改指令书需整顿问题列表
     * @param params
     */
    public void getOrderRectificationProblemList(LemonRequestParams params) {

        HandlerCallback<List<String>> callback = new HandlerCallback<List<String>>(KeyConstants.URL_ORDER_RECTIFICATION_PROBLEM) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.ORDER_RECTIFICATION_PROBLEM, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);

    }


    /**
     * 上传文书图片
     * @param params
     * @param fileMap
     */
    public void uploadDocPicture(LemonRequestParams params, Map<String, File> fileMap) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_UPLOAD_DOC_PICTURE_FILE) {
        };

        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.UPLOAD_DOC_PICTURE_FILE, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .addFiles("file", fileMap)
                .build().execute(callback);

    }

}
